﻿using LDM.Admin.Models.Base;
using LDM.Framework.NormalizeActionResult;
using LDM.Sys.ServiceAPI.Model.DBModel;
using LDM.Sys.ServiceAPI.Model.ViewModel.Request.AuthorityReq;
using LDM.Sys.ServiceAPI.Svc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace LDM.Admin.Controllers.Authority
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    public class AccountController : Controller
    {
        private IAccountService _accountService;
        public AccountController(IAccountService accountService)
        {
            _accountService = accountService;
        }

        [AllowAnonymous]
        public IActionResult Index()
        {
            return View();
        }



        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetSysAccounts(GetSysAccountReq request)
        {
            var result = await _accountService.GetSysAccounts(request);
            return Json(BaseGrid<SysAccount>.Instance(result));
        }

        /// <summary>
        ///  添加角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddAccount(AddSysAccountReq request)
        {
            await _accountService.AddSysAccount(request);
            return Json(ResultData.Success());
        }

        /// <summary>
        ///  修改角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<IActionResult> EditAccount(UpdateSysAccountReq request)
        {
            await _accountService.UpdateSysAccount(request);
            return Json(ResultData.Success());
        }

        /// <summary>
        ///  删除角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelAccount(DelSysAccountReq request)
        {
            await _accountService.DelSysAccount(request);
            return Json(ResultData.Success());
        }
    }
}
